<%-- 
    Document   : findFiles
    Created on : 1 déc. 2010, 18:30:55
    Author     : emugwaneza
--%>


<%@page import="java.io.FilenameFilter"%>
<%@page import="java.io.FileFilter"%>
<%@page import="java.io.File"%>
<%@page contentType="text/xml" pageEncoding="UTF-8"%>

<%

String keyT =(String) session.getAttribute("keyT");
System.out.println("keyT:"+ keyT);
if(keyT==null || keyT.isEmpty()){
    session.setAttribute("keyT", "ceci est un testouillie");
}


String sfile = request.getParameter("dir");
if(sfile==null ||sfile.isEmpty())
    sfile = "/home/emugwaneza";

final String filter = request.getParameter("filter");
System.out.println("filter:" + filter);
System.out.println("dir:" + sfile);
File dir = new File(sfile);
File[] lF;
if(filter!=null && !filter.isEmpty()){
FileFilter fil = new FileFilter() {
		public boolean accept(File file) {
		    String string = file.getName();
		    if(string.startsWith("."))
			return false;
		    
		    if(file.isDirectory())
			return true;
		    return string.endsWith(filter);
		}
	    };
lF = dir.listFiles(fil);
}else
    lF = dir.listFiles();

%>
<fichiers>
    <fic>
	<name>..</name>
	<isDir>true</isDir>
	<exactPath><%=dir.getParentFile().getAbsolutePath() %></exactPath>
<!--	<icon>/usr/share/icons/default.kde/64x64/actions/player_play.png</icon>-->
    </fic>
    <%
    for(File f:lF){

    %>
    <fic>
	<name><%= f.getName() %></name>
	<isDir><%=String.valueOf(f.isDirectory()) %></isDir>
	<exactPath><%=f.getAbsolutePath() %></exactPath>
<!--	<icon>/usr/share/icons/default.kde/64x64/actions/player_play.png</icon>-->
    </fic>
    <%}%>
</fichiers>
